﻿using System;
using System.Collections.Generic;
using System.ComponentModel;
using System.Data;
using System.Drawing;
using System.Linq;
using System.Text;
using System.Windows.Forms;
using ZedGraph;
using HTspcAppProject.Model;
using System.Configuration;
using HTDAL.HTSPC_DBDataSetTableAdapters;
using System.Threading;

namespace HTspcAppProject
{

    public partial class Form2 : Form
    {
        PointPairList list_room_set;
        PointPairList list_room_real;
        PointPairList list_oil_set;
        PointPairList list_oil_real;
        PointPairList list_cp_set;
        PointPairList list_cp_real;
        PointPairList list_cmv;
        /* ***************************************修改 0426 mqx****************************************** */
        PointPairList list_tl_real;
        PointPairList list_rx_real;

        GraphPane myPane1;
        GraphPane myPane2;
        GraphPane myPane3;
        GraphPane myPane4;
        int device_num;

        //private int point_count = 0;
        private XDate x_start;
        private XDate x_end;
        private double ScdDe = 0;//X坐标间隔

        private Form1 form1;
        //private Timer time;

        //y坐标范围
        double ymax = Convert.ToDouble(ConfigurationManager.AppSettings["ymax"]);
        double ymin = Convert.ToDouble(ConfigurationManager.AppSettings["ymin"]);

        RunSt rst = new RunSt();
        

        struct run_data
        {
            public float room_temp_set;
            public float room_temp_real;
            public float oil_temp_set;
            public float oil_temp_real;
            public float cp_value_set;
            public float cp_value_real;
            public float tl_value_set;
            public float tl_value_real;
            public float rx_value_set;
            public float rx_value_real;
            public float cmv_value;
            /* ***************************************wzy修改 2017 5-10****************************************** */
            //添加流量及油位数据
            public float tl_temp_set;
            public float tl_temp_real;
            public float rx_temp_set;
            public float rx_temp_real;
        }

        string devNm;

        public Form2()
        {
            InitializeComponent();
        }

        public bool jumpEnable = true;//跳转开关
        public Form2(int device_number, Form1 form1,bool jumpTag)
        {
            InitializeComponent();
            device_num = device_number;
            devNm = (string)CommonClass.devDtList.Rows[device_number-1]["devNm"];

            //版本2
            this.form1 = form1;

            this.WindowState = FormWindowState.Maximized;

            //label_title.Location = new Point(this.Width/2-label_title.Width/2,10);
            //label_title.Text = devNm + "运行情况(Furnace Running Condition)";
            //label_num.Text = "#" + device_number;

            list_oil_set = new PointPairList();
            list_room_real = new PointPairList();
            list_oil_real = new PointPairList();
            list_room_set = new PointPairList();
            list_cmv = new PointPairList();
            list_cp_set = new PointPairList();
            list_cp_real = new PointPairList();

           

            DateTime dt1 = DateTime.Now;
            DateTime dt2;
            /* ***************************************修改 10-12****************************************** */
            //读取配置文件中的x轴范围设置值
            string scalex = ConfigurationManager.AppSettings["scaleX"];
            int scalex_len = scalex.Length;
            if (scalex.Substring(scalex.Length - 1, 1) == "h")
                //dt2 = dt1.AddHours(-int.Parse(scalex.Substring(0, scalex_len - 1)));
                ScdDe = double.Parse(scalex.Substring(0, scalex_len - 1)) * 3600;
            else if (scalex.Substring(scalex.Length - 1, 1) == "m")
                ScdDe = double.Parse(scalex.Substring(0, scalex_len - 1)) * 60;
            else if (scalex.Substring(scalex.Length - 1, 1) == "s")
                ScdDe = double.Parse(scalex.Substring(0, scalex_len - 1));
            else
            {
                MessageBox.Show("配置文件中“X轴范围”填写错误！请输入正确格式，如2个小时则为“2h”。",
                    "异常", MessageBoxButtons.OK, MessageBoxIcon.Error);
                Application.Exit();
                return;
            }

            # region 工艺曲线预载入 2013-10-24
            dt2 = dt1.AddSeconds(-ScdDe);
            ht_pmlogTableAdapter pmlogTa = new ht_pmlogTableAdapter();
            DataTable pmlogDt = pmlogTa.GetDataByTime(dt2, dt1, devNm);
            if (pmlogDt.Rows.Count > 0)
            {
                float room_temp, oil_temp, cp, cmv;
                DateTime dt;
                dt1 = Convert.ToDateTime(pmlogDt.Rows[0]["dt"]);
                foreach (DataRow dr in pmlogDt.Rows)
                {
                    room_temp = Convert.ToSingle(dr["hswdCur"]);
                    oil_temp = Convert.ToSingle(dr["ycwdCur"]);
                    cp = Convert.ToSingle(dr["cpCur"]);
                    cmv = Convert.ToSingle(dr["CMV"]);
                    dt = Convert.ToDateTime(dr["dt"]);
                    HistoryAdd((XDate)dt, room_temp, oil_temp, cp, cmv);

                }
            }
            # endregion

            x_start = new XDate(dt1);

            x_end = new XDate(x_start.DateTime.AddSeconds(ScdDe));
            /* ***************************************修改 10-25****************************************** */
            //if (scalex.Substring(scalex.Length - 1, 1) == "h")
            //    x_end = new XDate(x_start.DateTime.AddHours(int.Parse(scalex.Substring(0, scalex_len - 1))));
            //if (scalex.Substring(scalex.Length - 1, 1) == "m")
            //    x_end = new XDate(x_start.DateTime.AddMinutes(int.Parse(scalex.Substring(0, scalex.Length - 1))));
            //if (scalex.Substring(scalex.Length - 1, 1) == "s")
            //    x_end = new XDate(x_start.DateTime.AddSeconds(int.Parse(scalex.Substring(0, scalex.Length - 1))));

            //ScdDe = (x_end.DateTime - x_start.DateTime).TotalSeconds;

            run_data new_data = new run_data();
            new_data.cp_value_set = 0;
            new_data.cp_value_real = 0;
            new_data.room_temp_set = 0;
            new_data.room_temp_real = 0;
            new_data.oil_temp_real = 0;
            new_data.oil_temp_set = 0;
            new_data.tl_value_set = 0;
            new_data.tl_value_real = 0;
            new_data.rx_value_set = 0;
            new_data.rx_value_real = 0;
            new_data.cmv_value = 0;
            
            SetValue(new_data);

            //设置部分元素位置
            // Set the Titles
            /* ***************************************修改 0426 mqx****************************************** */
            myPane1 = zedGraphControl1.GraphPane;
            myPane1.Title.Text = "1号机运行工艺曲线(Performance Curve)";
            myPane1.XAxis.Title.Text = "时间(Time)";
            //myPane.YAxis.Title.Text = "温度/值(Temp)";

            myPane1.XAxis.Type = AxisType.Date;
            myPane1.XAxis.Scale.Format = "HH:mm:ss";
            zedGraphControl1.PointDateFormat = "HH:mm:ss";
            myPane1.XAxis.MajorGrid.IsVisible = true;
            myPane1.YAxis.MajorGrid.IsVisible = true;
            myPane1.YAxis.Title.IsVisible = false;
            myPane1.YAxis.Scale.IsVisible = false;

            myPane1.YAxis.Scale.Max = ymax;
            myPane1.YAxis.Scale.Min = ymin;
            myPane1.XAxis.Scale.Max = (double)x_end;
            myPane1.XAxis.Scale.Min = (double)x_start;
            ///wzy 2017-05-10  2号机图
            myPane2 = zedGraphControl2.GraphPane;
            myPane2.Title.Text = "2号机运行工艺曲线(Performance Curve)";
            myPane2.XAxis.Title.Text = "时间(Time)";
            //myPane.YAxis.Title.Text = "温度/值(Temp)";

            myPane2.XAxis.Type = AxisType.Date;
            myPane2.XAxis.Scale.Format = "HH:mm:ss";
            zedGraphControl2.PointDateFormat = "HH:mm:ss";
            myPane2.XAxis.MajorGrid.IsVisible = true;
            myPane2.YAxis.MajorGrid.IsVisible = true;
            myPane2.YAxis.Title.IsVisible = false;
            myPane2.YAxis.Scale.IsVisible = false;

            myPane2.YAxis.Scale.Max = ymax;
            myPane2.YAxis.Scale.Min = ymin;
            myPane2.XAxis.Scale.Max = (double)x_end;
            myPane2.XAxis.Scale.Min = (double)x_start;
            ///wzy 2017-05-10 3号机图
            myPane3 = zedGraphControl3.GraphPane;
            myPane3.Title.Text = "3号机运行工艺曲线(Performance Curve)";
            myPane3.XAxis.Title.Text = "时间(Time)";
            //myPane.YAxis.Title.Text = "温度/值(Temp)";

            myPane3.XAxis.Type = AxisType.Date;
            myPane3.XAxis.Scale.Format = "HH:mm:ss";
            zedGraphControl3.PointDateFormat = "HH:mm:ss";
            myPane3.XAxis.MajorGrid.IsVisible = true;
            myPane3.YAxis.MajorGrid.IsVisible = true;
            myPane3.YAxis.Title.IsVisible = false;
            myPane3.YAxis.Scale.IsVisible = false;

            myPane3.YAxis.Scale.Max = ymax;
            myPane3.YAxis.Scale.Min = ymin;
            myPane3.XAxis.Scale.Max = (double)x_end;
            myPane3.XAxis.Scale.Min = (double)x_start;

            ///wzy 2017-05-10 4号机图
            myPane4 = zedGraphControl4.GraphPane;
            myPane4.Title.Text = "4号机运行工艺曲线(Performance Curve)";
            myPane4.XAxis.Title.Text = "时间(Time)";
            //myPane.YAxis.Title.Text = "温度/值(Temp)";

            myPane4.XAxis.Type = AxisType.Date;
            myPane4.XAxis.Scale.Format = "HH:mm:ss";
            zedGraphControl4.PointDateFormat = "HH:mm:ss";
            myPane4.XAxis.MajorGrid.IsVisible = true;
            myPane4.YAxis.MajorGrid.IsVisible = true;
            myPane4.YAxis.Title.IsVisible = false;
            myPane4.YAxis.Scale.IsVisible = false;

            myPane4.YAxis.Scale.Max = ymax;
            myPane4.YAxis.Scale.Min = ymin;
            myPane4.XAxis.Scale.Max = (double)x_end;
            myPane4.XAxis.Scale.Min = (double)x_start;
            //分别添加数据显示
            LineItem myCurve = myPane1.AddCurve("后室温度",
                  list_room_real, Color.Plum, SymbolType.None);
            LineItem myCurve21 = myPane2.AddCurve("后室温度",
                  list_room_real, Color.Plum, SymbolType.None);
            LineItem myCurve31 = myPane3.AddCurve("后室温度",
                 list_room_real, Color.Plum, SymbolType.None);
            LineItem myCurve41 = myPane4.AddCurve("后室温度",
                 list_room_real, Color.Plum, SymbolType.None);
            /* ***************************************修改 0426 mqx****************************************** */
            room_real1.BackColor = Color.Plum;
              room_real2.BackColor = Color.Plum;
              room_real3.BackColor = Color.Plum;
              room_real4.BackColor = Color.Plum;
            myCurve.Line.Width = CommonClass.SlineW;
            myCurve21.Line.Width = CommonClass.SlineW;
            myCurve31.Line.Width = CommonClass.SlineW;
            myCurve41.Line.Width = CommonClass.SlineW;

            LineItem myCurve2 = myPane1.AddCurve("油槽温度",
                  list_oil_real, Color.Lime, SymbolType.None);
            LineItem myCurve22 = myPane2.AddCurve("油槽温度",
                 list_oil_real, Color.Lime, SymbolType.None);
            LineItem myCurve32 = myPane3.AddCurve("油槽温度",
                 list_oil_real, Color.Lime, SymbolType.None);
            LineItem myCurve42 = myPane4.AddCurve("油槽温度",
                 list_oil_real, Color.Lime, SymbolType.None);
            /* ***************************************修改 0426 mqx****************************************** */
            oil_real1.BackColor = Color.Lime;
            oil_real2.BackColor = Color.Lime;
            oil_real3.BackColor = Color.Lime;
            oil_real4.BackColor = Color.Lime;
            myCurve2.Line.Width = CommonClass.SlineW;
            myCurve22.Line.Width = CommonClass.SlineW;
            myCurve32.Line.Width = CommonClass.SlineW;
            myCurve42.Line.Width = CommonClass.SlineW;

            LineItem myCurve3 = myPane1.AddCurve("CP值",
                  list_cp_real, Color.DeepSkyBlue, SymbolType.None);
            LineItem myCurve23 = myPane2.AddCurve("CP值",
                  list_cp_real, Color.DeepSkyBlue, SymbolType.None);
            LineItem myCurve33 = myPane3.AddCurve("CP值",
                  list_cp_real, Color.DeepSkyBlue, SymbolType.None);
            LineItem myCurve43 = myPane4.AddCurve("CP值",
                  list_cp_real, Color.DeepSkyBlue, SymbolType.None);
            /* ***************************************修改 0426 mqx****************************************** */
            cp_real1.BackColor = Color.DeepSkyBlue;
            cp_real2.BackColor = Color.DeepSkyBlue;
            cp_real3.BackColor = Color.DeepSkyBlue;
            cp_real4.BackColor = Color.DeepSkyBlue;
            myCurve3.Line.Width = CommonClass.SlineW;
            myCurve23.Line.Width = CommonClass.SlineW;
            myCurve33.Line.Width = CommonClass.SlineW;
            myCurve43.Line.Width = CommonClass.SlineW;

            LineItem myCurve4 = myPane1.AddCurve("CMV阀开度",
                  list_cmv, Color.Orange, SymbolType.None);
            LineItem myCurve24 = myPane2.AddCurve("CMV阀开度",
                  list_cmv, Color.Orange, SymbolType.None);
            LineItem myCurve34 = myPane3.AddCurve("CMV阀开度",
                  list_cmv, Color.Orange, SymbolType.None);
            LineItem myCurve44 = myPane4.AddCurve("CMV阀开度",
                  list_cmv, Color.Orange, SymbolType.None);
            /* ***************************************修改 0426 mqx****************************************** */
            cmv_val1.BackColor = Color.Orange;
            cmv_val2.BackColor = Color.Orange;
            cmv_val3.BackColor = Color.Orange;
            cmv_val4.BackColor = Color.Orange;
            myCurve4.Line.Width = CommonClass.SlineW;
            myCurve24.Line.Width = CommonClass.SlineW;
            myCurve34.Line.Width = CommonClass.SlineW;
            myCurve44.Line.Width = CommonClass.SlineW;

            LineItem myCurve5 = myPane1.AddCurve("油槽液位",
                 list_tl_real, Color.Yellow, SymbolType.None);
            LineItem myCurve25 = myPane2.AddCurve("油槽液位",
                 list_tl_real, Color.Yellow, SymbolType.None);
            LineItem myCurve35 = myPane3.AddCurve("油槽液位",
                 list_tl_real, Color.Yellow, SymbolType.None);
            LineItem myCurve45 = myPane4.AddCurve("油槽液位",
                 list_tl_real, Color.Yellow, SymbolType.None);
            tl_real1.BackColor = Color.Yellow;
            tl_real2.BackColor = Color.Yellow;
            tl_real3.BackColor = Color.Yellow;
            tl_real4.BackColor = Color.Yellow;
            myCurve5.Line.Width = CommonClass.SlineW;
            myCurve25.Line.Width = CommonClass.SlineW;
            myCurve35.Line.Width = CommonClass.SlineW;
            myCurve45.Line.Width = CommonClass.SlineW;

            LineItem myCurve6 = myPane1.AddCurve("RX气体流量",
                list_rx_real, Color.Magenta, SymbolType.None);
            LineItem myCurve26 = myPane2.AddCurve("RX气体流量",
               list_rx_real, Color.Magenta, SymbolType.None);
            LineItem myCurve36 = myPane3.AddCurve("RX气体流量",
               list_rx_real, Color.Magenta, SymbolType.None);
            LineItem myCurve46 = myPane4.AddCurve("RX气体流量",
               list_rx_real, Color.Magenta, SymbolType.None);
            myCurve6.Line.Width = CommonClass.SlineW;
            myCurve26.Line.Width = CommonClass.SlineW;
            myCurve36.Line.Width = CommonClass.SlineW;
            myCurve46.Line.Width = CommonClass.SlineW;
            // 当坐标系变化时，需要调用该函数进行刷新
            zedGraphControl1.AxisChange();
            zedGraphControl1.Refresh();
            zedGraphControl2.AxisChange();
            zedGraphControl2.Refresh();
            zedGraphControl3.AxisChange();
            zedGraphControl3.Refresh();
            zedGraphControl4.AxisChange();
            zedGraphControl4.Refresh();
            timer1.Enabled = true;
        }
        //private void time_Tick(Object sender, EventArgs e)
        //{
        //    //if (device_num == CommonClass.devDtList.Rows.Count)
        //    //{
        //    //    time.Enabled = false;
        //    //    this.Close();
        //    //    form1.Show();
        //    //    form1.Time.Enabled = true;
        //    //}
        //    //else
        //    //{
        //    //    time.Enabled = false;
        //    //    this.Close();
        //    //    Form2 form2 = new Form2(device_num + 1, form1,true);
        //    //    form2.Show();
        //    //}
        //}


        private void Form2_FormClosed(object sender, FormClosedEventArgs e)
        {
            //根据情况不同，两个版本不一样,自动调整版本，请注释该行
            //form1.Show();
           
        }

        private void zedGraphControl1_Load(object sender, EventArgs e)
        {
            /*
            zedgraphControl.AxisChange();
            */
        }

        private void SetValue(run_data data)
        {
            //依次将界面上的对应text值更新
            room_set1.Text = Convert.ToString(data.room_temp_set);
            room_real1.Text = Convert.ToString(data.room_temp_real);

            oil_set1.Text = Convert.ToString(data.oil_temp_set);
            oil_real1.Text = Convert.ToString(data.oil_temp_real);

            cp_set1.Text = Convert.ToString(data.cp_value_set);
            cp_real1.Text = Convert.ToString(data.cp_value_real);

            //不知道;工艺编号等是否持续变化

        }

        private void Form2_Load(object sender, EventArgs e)
        {
            //每隔一秒添加一个点
            //Timer time_test = new Timer();
            //time_test.Enabled = true;
            //time_test.Interval = 1000;

            //time_test.Tick +=new EventHandler(time_test_Tick);

        }

        //private void time_test_Tick(object sender, System.EventArgs e)
        //{
        //    ht_pmmr new_data = new ht_pmmr();
        //    new_data.cpSet = new Random().Next(5);
        //    new_data.ycwdSer = new Random().Next(5) - 2;
        //    new_data.hswdSet = new Random().Next(5);
        //    new_data.cpCur = new Random().Next(5) + 1;
        //    new_data.ycwdCur = new Random().Next(5) + 2;
        //    new_data.hswdCur = new Random().Next(5) - 1;
        //    new_data.CMV = new Random().Next(5) + 3;

        //    AddPoint(new_data);
        //}

        private void AddPoint(ht_pmmr data,ZedGraphControl zedgraphcontrol)
        {
            //根据传过来的data，将界面更新
            XDate now = new XDate(DateTime.Now);
            double add_time = (double)now;

            //叶岍 2013-10-13 增加因数成绩
            /* ***************************************略修改 10-12****************************************** */
            //将数据范围进行协调，使得界面显示好看
            list_room_real.Add(add_time, Convert.ToDouble(data.hswdCur * CommonClass.hsy));
            list_oil_real.Add(add_time, Convert.ToDouble(data.ycwdCur * CommonClass.ycy));
            list_cp_real.Add(add_time, Convert.ToDouble(data.cpCur * CommonClass.cpy));
            list_cmv.Add(add_time, Convert.ToDouble(data.CMV * CommonClass.cmvy));

            ////point_count++;
            /* ***************************************优化不连续时间添加点后产生的bug 10-21****************************************** */
            try
            {
                if (now.CompareTo(x_end) > 0)
                {
                    //可以将各类数据的第一个元素剔除
                    if ((XDate)(list_cp_real[0].X) > x_start)
                    {
                        try
                        {
                            list_cp_real.RemoveAt(0);
                            list_oil_real.RemoveAt(0);
                            list_room_real.RemoveAt(0);
                            list_cmv.RemoveAt(0);
                        }
                        catch (ArgumentOutOfRangeException)
                        { }
                    }
                    //这里修改了x轴最大值的增加幅度为3，避免最后一个值出现在屏幕最右边
                    x_start = x_end.DateTime.AddSeconds(-ScdDe);
                    x_end = now;
                    x_end.AddSeconds(2);

                    myPane1.XAxis.Scale.Max = (double)x_end;
                    myPane1.XAxis.Scale.Min = (double)x_start;
                    myPane2.XAxis.Scale.Max = (double)x_end;
                    myPane2.XAxis.Scale.Min = (double)x_start;
                    myPane2.XAxis.Scale.Max = (double)x_end;
                    myPane3.XAxis.Scale.Min = (double)x_start;
                    myPane3.XAxis.Scale.Max = (double)x_end;
                    myPane4.XAxis.Scale.Min = (double)x_start;
                    myPane4.XAxis.Scale.Max = (double)x_end;
                    x_end.AddSeconds(-2);
                }
            }
            catch (Exception ex)
            {
                CommonClass.LogError(ex.ToString());
            }

            zedgraphcontrol.AxisChange();
            zedgraphcontrol.Refresh();
            //x_end.AddSeconds(-3);


        }

        //private void Form2_Resize(object sender, EventArgs e)
        //{
        //    zedgraphControl.Size = new Size(this.Size.Width - zedgraphControl.Location.X - 40, zedgraphControl.Size.Height);
        //}

        private void button_history_Click(object sender, EventArgs e)
        {
            //将历史曲线界面显示出来
            PointPairList hisRoomPoint = new PointPairList(list_room_real);
            PointPairList hitOilPoint = new PointPairList(list_oil_real);
            PointPairList hisCpPoint = new PointPairList(list_cp_real);
            PointPairList hisCmvPoint = new PointPairList(list_cmv);
            History history = new History(device_num, devNm, hisRoomPoint, hitOilPoint, hisCpPoint, hisCmvPoint);
            history.Show();
        }

        private void button_war_Click(object sender, EventArgs e)
        {
            FormWarInfo fwi = new FormWarInfo(device_num, devNm);
            jumpEnable = false;
            if (fwi.ShowDialog() == System.Windows.Forms.DialogResult.OK)
            {
                //tbxWarInfo.Clear();
                //warPanel.Visible = false;
                pictureBox1.BackColor = Color.White;
                hstag = true;
                YcTag = true;
            }
        }

        private void time_begin_TextChanged(object sender, EventArgs e)
        {

        }

        private void time_begin_Click(object sender, EventArgs e)
        {
            //点击编辑，清楚原数据
        }

        private void time_end_Click(object sender, EventArgs e)
        {

        }

        private void button1_Click(object sender, EventArgs e)
        {
            //点击确定搜索按钮后，将按照所输入时间范围进行查找
        }

        private void button_all_Click(object sender, EventArgs e)
        {
            jumpEnable = false;
            this.Hide();
            form1.Show();
        }

        private void Form2_SizeChanged(object sender, EventArgs e)
        {
            //label_title.Location = new Point(this.Width / 2 - label_title.Width / 2, 10);
        }


        bool hstag = true;//后室温度报警标识
        bool YcTag = true;//油槽温度报警标识
        int offTime = 0; //1号机停机或离线时间
        int offTime2 = 0;//2号机停机或离线时间
        int offTime3 = 0;//3号机停机或离线时间
        int offTime4 = 0;//4号机停机或离线时间
        private void timer1_Tick(object sender, EventArgs e)
        {
            ht_pmmr pmmr = CommonClass.pmDict[devNm];
            #region 原程序
            //number_val1.Text = pmmr.gyid;

            //room_set1.Text = Convert.ToString(Convert.ToDecimal(pmmr.hswdSet ?? 0).ToString("N2"));
            //room_real1.Text = Convert.ToString(Convert.ToDecimal(pmmr.hswdCur ?? 0).ToString("N2"));
            //hswdlab1.Text = room_real1.Text;

            //tl_set1.Text = Convert.ToDecimal(pmmr.ycwdSer ?? 0).ToString("N2");
            //oil_real1.Text = Convert.ToDecimal(pmmr.ycwdCur ?? 0).ToString("N2");
            //ycwdlab1.Text = oil_real1.Text;

            //cp_set1.Text = Convert.ToDecimal(pmmr.cpSet).ToString("N2");
            //cp_real1.Text = Convert.ToDecimal(pmmr.cpCur).ToString("N2");
            //cplab1.Text = cp_real1.Text;

            //cmv_val1.Text = Convert.ToDecimal(pmmr.CMV).ToString("N2");
            //cmvlab1.Text = cmv_val1.Text;
            //double hswdMax = Convert.ToDouble(CommonClass.devDtList.Rows[device_num - 1]["hswdMax"]);
            //double ycwdMax = Convert.ToDouble(CommonClass.devDtList.Rows[device_num - 1]["ycwdMax"]);


            //if (pmmr.hswdCur == 0 || pmmr.hswdCur == null || pmmr.st == "2")
            //{
            //    state_val1.Text = "离线";
            //    state_val1.ForeColor = Color.Silver;
            //    offTime++;
            //}
            //else if (pmmr.hswdCur < 400)
            //{
            //    state_val1.Text = "停机";
            //    state_val1.ForeColor = Color.Red;
            //    if (pmmr.hswdCur > 0)
            //    {
            //        prdStClear();
            //    }
            //    else
            //    {
            //        offTime++;
            //    }
            //    try
            //    {
            //        AddPoint(pmmr, zedGraphControl1);
            //    }
            //    catch (Exception ex)
            //    {
            //        CommonClass.LogError(ex.ToString());
            //    }
            //}
            //else
            //{
            //    offTime = 0;
            //    //后室报警判断
            //    if (hswdMax > 0 && pmmr.hswdCur > hswdMax && hstag)
            //    {
            //        splitContainer2.Panel1.BackColor = Color.Red;
            //        WaringSol(pmmr, "后室温度超过温度上限！" + "后室温度：" + ((double)(pmmr.hswdCur)).ToString("N2") + "℃",
            //                    "后室上限温度：" + hswdMax.ToString("N2") + "℃");
            //        hstag = false;
            //    }
            //    else if (hswdMax > 0 && pmmr.hswdCur < hswdMax && !hstag)
            //    {
            //        hstag = true;
            //        pictureBox1.BackColor = Color.White;
            //        splitContainer2.Panel1.BackColor = Color.Black;
            //    }
            //    //油槽报警判断
            //    if (ycwdMax > 0 && pmmr.ycwdCur > ycwdMax && YcTag)
            //    {
            //        splitContainer3.Panel1.BackColor = Color.Red;
            //        WaringSol(pmmr, "油槽温度超过温度上限！" + "油槽温度：" + ((double)(pmmr.ycwdCur)).ToString("N2") + "℃",
            //                "油槽上限温度：" + ycwdMax.ToString("N2") + "℃");
            //        YcTag = false;
            //    }
            //    else if (ycwdMax > 0 && pmmr.ycwdCur < ycwdMax && !YcTag)
            //    {
            //        YcTag = true;
            //        pictureBox1.BackColor = Color.White;
            //        splitContainer3.Panel1.BackColor = Color.Black;
            //    }

            //    state_val1.Text = "运行";
            //    state_val1.ForeColor = Color.Black;
            //    try
            //    {
            //        AddPoint(pmmr, zedGraphControl1);
            //    }
            //    catch (Exception ex)
            //    {
            //        CommonClass.LogError(ex.ToString());
            //    }

            //    WorkStGet(pmmr);//状态解析
            //}
            //if (offTime > 30)
            //{
            //    prdStClear();
            //}
            #endregion
            ///1号机
            number_val1.Text = CommonClass.pmDict["1号加热炉"].gyid;

            room_set1.Text = Convert.ToString(Convert.ToDecimal(CommonClass.pmDict["1号加热炉"].hswdSet??0).ToString("N2"));
            room_real1.Text = Convert.ToString(Convert.ToDecimal(CommonClass.pmDict["1号加热炉"].hswdCur ?? 0).ToString("N2"));
            hswdlab1.Text = room_real1.Text;

            tl_set1.Text = Convert.ToString(Convert.ToDecimal(CommonClass.pmDict["1号加热炉"].tlSet ?? 0).ToString("N2"));
            tl_real1.Text = Convert.ToString(Convert.ToDecimal(CommonClass.pmDict["1号加热炉"].tlCur ?? 0).ToString("N2"));
            tllab1.Text = tl_real1.Text;

            rx_set1.Text = Convert.ToString(Convert.ToDecimal(CommonClass.pmDict["1号加热炉"].RxSet ?? 0).ToString("N2"));
            rx_real1.Text = Convert.ToString(Convert.ToDecimal(CommonClass.pmDict["1号加热炉"].RxCur ?? 0).ToString("N2"));
            rxlab1.Text = rx_real1.Text;

            oil_set1.Text = Convert.ToDecimal(CommonClass.pmDict["1号加热炉"].ycwdSer ?? 0).ToString("N2");
            oil_real1.Text = Convert.ToDecimal(CommonClass.pmDict["1号加热炉"].ycwdCur ?? 0).ToString("N2");
            ycwdlab1.Text = oil_real1.Text;

            cp_set1.Text = Convert.ToDecimal(CommonClass.pmDict["1号加热炉"].cpSet).ToString("N2");
            cp_real1.Text = Convert.ToDecimal(CommonClass.pmDict["1号加热炉"].cpCur).ToString("N2");
            cplab1.Text = cp_real1.Text;

            cmv_val1.Text = Convert.ToDecimal(CommonClass.pmDict["1号加热炉"].CMV).ToString("N2");
            cmvlab1.Text = cmv_val1.Text;
            double hswdMax1 = Convert.ToDouble(CommonClass.devDtList.Rows[0]["hswdMax"]);
            double ycwdMax1 = Convert.ToDouble(CommonClass.devDtList.Rows[0]["ycwdMax"]);
            if (CommonClass.pmDict["1号加热炉"].hswdCur == 0 || CommonClass.pmDict["1号加热炉"].hswdCur == null || CommonClass.pmDict["1号加热炉"].st == "2")
            {
                state_val1.Text = "离线";
                state_val1.ForeColor = Color.Silver;
                offTime++;
            }
            else if (CommonClass.pmDict["1号加热炉"].hswdCur < 400)
            {
                state_val1.Text = "停机";
                state_val1.ForeColor = Color.Red;
                if (CommonClass.pmDict["1号加热炉"].hswdCur > 0)
                {
                    prdStClear("1号加热炉");
                }
                else
                {
                    offTime++;
                }
                try
                {
                    AddPoint(CommonClass.pmDict["1号加热炉"], zedGraphControl1);
                }
                catch(Exception ex)
                {
                    CommonClass.LogError(ex.ToString());
                }
            }
            else
            {
                offTime = 0;
                //后室报警判断
                if (hswdMax1 > 0 && CommonClass.pmDict["1号加热炉"].hswdCur > hswdMax1 && hstag)
                {
                    splitContainer2.Panel1.BackColor = Color.Red;
                    WaringSol(CommonClass.pmDict["1号加热炉"], "后室温度超过温度上限！" + "后室温度：" + ((double)(CommonClass.pmDict["1号加热炉"].hswdCur)).ToString("N2") + "℃",
                                "后室上限温度：" + hswdMax1.ToString("N2") + "℃");
                    hstag = false;
                }
                else if (hswdMax1 > 0  && CommonClass.pmDict["1号加热炉"].hswdCur < hswdMax1&&!hstag)
                {
                    hstag = true;
                    pictureBox1.BackColor = Color.White;
                    splitContainer2.Panel1.BackColor = Color.Black;
                }
                //油槽报警判断
                if (ycwdMax1 > 0 && CommonClass.pmDict["1号加热炉"].ycwdCur > ycwdMax1 && YcTag)
                {
                    splitContainer3.Panel1.BackColor = Color.Red;
                    WaringSol(CommonClass.pmDict["1号加热炉"], "油槽温度超过温度上限！" + "油槽温度：" + ((double)(CommonClass.pmDict["1号加热炉"].ycwdCur)).ToString("N2") + "℃",
                            "油槽上限温度：" + ycwdMax1.ToString("N2") + "℃");
                    YcTag = false;
                }
                else if (ycwdMax1 > 0 && CommonClass.pmDict["1号加热炉"].ycwdCur < ycwdMax1 && !YcTag)
                {
                    YcTag = true;
                    pictureBox1.BackColor = Color.White;
                    splitContainer3.Panel1.BackColor = Color.Black;
                }

                state_val1.Text = "运行";
                state_val1.ForeColor = Color.Black;
                try
                {
                    AddPoint(CommonClass.pmDict["1号加热炉"], zedGraphControl1);
                }
                catch (Exception ex)
                {
                    CommonClass.LogError(ex.ToString());
                }
                
                WorkStGet(CommonClass.pmDict["1号加热炉"]);//状态解析
            }
            if (offTime > 30)
            {
                prdStClear("1号加热炉");
            }
            ///2号机
            number_val2.Text = CommonClass.pmDict["2号加热炉"].gyid;

            room_set2.Text = Convert.ToString(Convert.ToDecimal(CommonClass.pmDict["2号加热炉"].hswdSet ?? 0).ToString("N2"));
            room_real2.Text = Convert.ToString(Convert.ToDecimal(CommonClass.pmDict["2号加热炉"].hswdCur ?? 0).ToString("N2"));
            hswdlab2.Text = room_real2.Text;

            oil_set2.Text = Convert.ToDecimal(CommonClass.pmDict["2号加热炉"].ycwdSer ?? 0).ToString("N2");
            oil_real2.Text = Convert.ToDecimal(CommonClass.pmDict["2号加热炉"].ycwdCur ?? 0).ToString("N2");
            ycwdlab2.Text = oil_real2.Text;

            cp_set2.Text = Convert.ToDecimal(CommonClass.pmDict["2号加热炉"].cpSet).ToString("N2");
            cp_real2.Text = Convert.ToDecimal(CommonClass.pmDict["2号加热炉"].cpCur).ToString("N2");
            cplab2.Text = cp_real2.Text;

            tl_set2.Text = Convert.ToString(Convert.ToDecimal(CommonClass.pmDict["2号加热炉"].tlSet ?? 0).ToString("N2"));
            tl_real2.Text = Convert.ToString(Convert.ToDecimal(CommonClass.pmDict["2号加热炉"].tlCur ?? 0).ToString("N2"));
            tllab2.Text = tl_real2.Text;

            rx_set2.Text = Convert.ToString(Convert.ToDecimal(CommonClass.pmDict["2号加热炉"].RxSet ?? 0).ToString("N2"));
            rx_real2.Text = Convert.ToString(Convert.ToDecimal(CommonClass.pmDict["2号加热炉"].RxCur ?? 0).ToString("N2"));
            rxlab2.Text = rx_real2.Text;

            cmv_val2.Text = Convert.ToDecimal(CommonClass.pmDict["2号加热炉"].CMV).ToString("N2");
            cmvlab2.Text = cmv_val2.Text;
            double hswdMax2 = Convert.ToDouble(CommonClass.devDtList.Rows[1]["hswdMax"]);
            double ycwdMax2 = Convert.ToDouble(CommonClass.devDtList.Rows[1]["ycwdMax"]);
            if (CommonClass.pmDict["2号加热炉"].hswdCur == 0 || CommonClass.pmDict["2号加热炉"].hswdCur == null || CommonClass.pmDict["2号加热炉"].st == "2")
            {
                state_val2.Text = "离线";
                state_val2.ForeColor = Color.Silver;
                offTime2++;
            }
            else if (CommonClass.pmDict["2号加热炉"].hswdCur < 400)
            {
                state_val2.Text = "停机";
                state_val2.ForeColor = Color.Red;
                if (CommonClass.pmDict["2号加热炉"].hswdCur > 0)
                {
                    prdStClear("2号加热炉");
                }
                else
                {
                    offTime2++;
                }
                try
                {
                    AddPoint(CommonClass.pmDict["2号加热炉"], zedGraphControl2);
                }
                catch (Exception ex)
                {
                    CommonClass.LogError(ex.ToString());
                }
            }
            else
            {
                offTime2 = 0;
                //后室报警判断
                if (hswdMax2 > 0 && CommonClass.pmDict["2号加热炉"].hswdCur > hswdMax2 && hstag)
                {
                    splitContainer2.Panel1.BackColor = Color.Red;
                    WaringSol(CommonClass.pmDict["2号加热炉"], "后室温度超过温度上限！" + "后室温度：" + ((double)(CommonClass.pmDict["2号加热炉"].hswdCur)).ToString("N2") + "℃",
                                "后室上限温度：" + hswdMax2.ToString("N2") + "℃");
                    hstag = false;
                }
                else if (hswdMax2 > 0 && CommonClass.pmDict["2号加热炉"].hswdCur < hswdMax2 && !hstag)
                {
                    hstag = true;
                    pictureBox1.BackColor = Color.White;
                    splitContainer2.Panel1.BackColor = Color.Black;
                }
                //油槽报警判断
                if (ycwdMax2 > 0 && CommonClass.pmDict["2号加热炉"].ycwdCur > ycwdMax2 && YcTag)
                {
                    splitContainer3.Panel1.BackColor = Color.Red;
                    WaringSol(CommonClass.pmDict["2号加热炉"], "油槽温度超过温度上限！" + "油槽温度：" + ((double)(CommonClass.pmDict["2号加热炉"].ycwdCur)).ToString("N2") + "℃",
                            "油槽上限温度：" + ycwdMax2.ToString("N2") + "℃");
                    YcTag = false;
                }
                else if (ycwdMax2 > 0 && CommonClass.pmDict["2号加热炉"].ycwdCur < ycwdMax2 && !YcTag)
                {
                    YcTag = true;
                    pictureBox1.BackColor = Color.White;
                    splitContainer3.Panel1.BackColor = Color.Black;
                }

                state_val2.Text = "运行";
                state_val2.ForeColor = Color.Black;
                try
                {
                    AddPoint(CommonClass.pmDict["2号加热炉"], zedGraphControl2);
                }
                catch (Exception ex)
                {
                    CommonClass.LogError(ex.ToString());
                }

                WorkStGet(CommonClass.pmDict["2号加热炉"]);//状态解析
            }
            if (offTime > 30)
            {
                prdStClear("2号加热炉");
            }

            ///3号机
            number_val3.Text = CommonClass.pmDict["3号加热炉"].gyid;

            room_set3.Text = Convert.ToString(Convert.ToDecimal(CommonClass.pmDict["3号加热炉"].hswdSet ?? 0).ToString("N2"));
            room_real3.Text = Convert.ToString(Convert.ToDecimal(CommonClass.pmDict["3号加热炉"].hswdCur ?? 0).ToString("N2"));
            hswdlab3.Text = room_real3.Text;

            oil_set3.Text = Convert.ToDecimal(CommonClass.pmDict["3号加热炉"].ycwdSer ?? 0).ToString("N2");
            oil_real3.Text = Convert.ToDecimal(CommonClass.pmDict["3号加热炉"].ycwdCur ?? 0).ToString("N2");
            ycwdlab3.Text = oil_real3.Text;

            cp_set3.Text = Convert.ToDecimal(CommonClass.pmDict["3号加热炉"].cpSet).ToString("N2");
            cp_real3.Text = Convert.ToDecimal(CommonClass.pmDict["3号加热炉"].cpCur).ToString("N2");
            cplab3.Text = cp_real3.Text;

            tl_set3.Text = Convert.ToString(Convert.ToDecimal(CommonClass.pmDict["3号加热炉"].tlSet ?? 0).ToString("N2"));
            tl_real3.Text = Convert.ToString(Convert.ToDecimal(CommonClass.pmDict["3号加热炉"].tlCur ?? 0).ToString("N2"));
            tllab3.Text = tl_real3.Text;

            rx_set3.Text = Convert.ToString(Convert.ToDecimal(CommonClass.pmDict["3号加热炉"].RxSet ?? 0).ToString("N2"));
            rx_real3.Text = Convert.ToString(Convert.ToDecimal(CommonClass.pmDict["3号加热炉"].RxCur ?? 0).ToString("N2"));
            rxlab3.Text = rx_real3.Text;

            cmv_val3.Text = Convert.ToDecimal(CommonClass.pmDict["3号加热炉"].CMV).ToString("N2");
            cmvlab3.Text = cmv_val3.Text;
            double hswdMax3 = Convert.ToDouble(CommonClass.devDtList.Rows[2]["hswdMax"]);
            double ycwdMax3 = Convert.ToDouble(CommonClass.devDtList.Rows[2]["ycwdMax"]);
            if (CommonClass.pmDict["3号加热炉"].hswdCur == 0 || CommonClass.pmDict["3号加热炉"].hswdCur == null || CommonClass.pmDict["3号加热炉"].st == "2")
            {
                state_val3.Text = "离线";
                state_val3.ForeColor = Color.Silver;
                offTime3++;
            }
            else if (CommonClass.pmDict["3号加热炉"].hswdCur < 400)
            {
                state_val3.Text = "停机";
                state_val3.ForeColor = Color.Red;
                if (CommonClass.pmDict["3号加热炉"].hswdCur > 0)
                {
                    prdStClear("3号加热炉");
                }
                else
                {
                    offTime3++;
                }
                try
                {
                    AddPoint(CommonClass.pmDict["3号加热炉"], zedGraphControl3);
                }
                catch (Exception ex)
                {
                    CommonClass.LogError(ex.ToString());
                }
            }
            else
            {
                offTime3 = 0;
                //后室报警判断
                if (hswdMax3 > 0 && CommonClass.pmDict["3号加热炉"].hswdCur > hswdMax3 && hstag)
                {
                    splitContainer2.Panel1.BackColor = Color.Red;
                    WaringSol(CommonClass.pmDict["3号加热炉"], "后室温度超过温度上限！" + "后室温度：" + ((double)(CommonClass.pmDict["3号加热炉"].hswdCur)).ToString("N2") + "℃",
                                "后室上限温度：" + hswdMax3.ToString("N2") + "℃");
                    hstag = false;
                }
                else if (hswdMax3 > 0 && CommonClass.pmDict["3号加热炉"].hswdCur < hswdMax3 && !hstag)
                {
                    hstag = true;
                    pictureBox1.BackColor = Color.White;
                    splitContainer2.Panel1.BackColor = Color.Black;
                }
                //油槽报警判断
                if (ycwdMax3 > 0 && CommonClass.pmDict["3号加热炉"].ycwdCur > ycwdMax3 && YcTag)
                {
                    splitContainer3.Panel1.BackColor = Color.Red;
                    WaringSol(CommonClass.pmDict["3号加热炉"], "油槽温度超过温度上限！" + "油槽温度：" + ((double)(CommonClass.pmDict["3号加热炉"].ycwdCur)).ToString("N2") + "℃",
                            "油槽上限温度：" + ycwdMax3.ToString("N2") + "℃");
                    YcTag = false;
                }
                else if (ycwdMax3 > 0 && CommonClass.pmDict["3号加热炉"].ycwdCur < ycwdMax3 && !YcTag)
                {
                    YcTag = true;
                    pictureBox1.BackColor = Color.White;
                    splitContainer3.Panel1.BackColor = Color.Black;
                }

                state_val3.Text = "运行";
                state_val3.ForeColor = Color.Black;
                try
                {
                    AddPoint(CommonClass.pmDict["3号加热炉"], zedGraphControl3);
                }
                catch (Exception ex)
                {
                    CommonClass.LogError(ex.ToString());
                }

                WorkStGet(CommonClass.pmDict["3号加热炉"]);//状态解析
            }
            if (offTime3 > 30)
            {
                prdStClear("3号加热炉");
            }
            ///4号机
            number_val4.Text = CommonClass.pmDict["4号加热炉"].gyid;

            room_set4.Text = Convert.ToString(Convert.ToDecimal(CommonClass.pmDict["4号加热炉"].hswdSet ?? 0).ToString("N2"));
            room_real4.Text = Convert.ToString(Convert.ToDecimal(CommonClass.pmDict["4号加热炉"].hswdCur ?? 0).ToString("N2"));
            hswdlab4.Text = room_real4.Text;

            oil_set4.Text = Convert.ToDecimal(CommonClass.pmDict["4号加热炉"].ycwdSer ?? 0).ToString("N2");
            oil_real4.Text = Convert.ToDecimal(CommonClass.pmDict["4号加热炉"].ycwdCur ?? 0).ToString("N2");
            ycwdlab4.Text = oil_real4.Text;

            cp_set4.Text = Convert.ToDecimal(CommonClass.pmDict["4号加热炉"].cpSet).ToString("N2");
            cp_real4.Text = Convert.ToDecimal(CommonClass.pmDict["4号加热炉"].cpCur).ToString("N2");
            cplab4.Text = cp_real4.Text;

            tl_set4.Text = Convert.ToString(Convert.ToDecimal(CommonClass.pmDict["4号加热炉"].tlSet ?? 0).ToString("N2"));
            tl_real4.Text = Convert.ToString(Convert.ToDecimal(CommonClass.pmDict["4号加热炉"].tlCur ?? 0).ToString("N2"));
            tllab4.Text = tl_real4.Text;

            rx_set4.Text = Convert.ToString(Convert.ToDecimal(CommonClass.pmDict["4号加热炉"].RxSet ?? 0).ToString("N2"));
            rx_real4.Text = Convert.ToString(Convert.ToDecimal(CommonClass.pmDict["4号加热炉"].RxCur ?? 0).ToString("N2"));
            rxlab4.Text = rx_real4.Text;

            cmv_val4.Text = Convert.ToDecimal(CommonClass.pmDict["4号加热炉"].CMV).ToString("N2");
            cmvlab4.Text = cmv_val4.Text;
            double hswdMax4 = Convert.ToDouble(CommonClass.devDtList.Rows[0]["hswdMax"]);
            double ycwdMax4 = Convert.ToDouble(CommonClass.devDtList.Rows[0]["ycwdMax"]);
            if (CommonClass.pmDict["4号加热炉"].hswdCur == 0 || CommonClass.pmDict["4号加热炉"].hswdCur == null || CommonClass.pmDict["4号加热炉"].st == "2")
            {
                state_val4.Text = "离线";
                state_val4.ForeColor = Color.Silver;
                offTime4++;
            }
            else if (CommonClass.pmDict["4号加热炉"].hswdCur < 400)
            {
                state_val4.Text = "停机";
                state_val4.ForeColor = Color.Red;
                if (CommonClass.pmDict["4号加热炉"].hswdCur > 0)
                {
                    prdStClear("4号加热炉");
                }
                else
                {
                    offTime4++;
                }
                try
                {
                    AddPoint(CommonClass.pmDict["4号加热炉"], zedGraphControl3);
                }
                catch (Exception ex)
                {
                    CommonClass.LogError(ex.ToString());
                }
            }
            else
            {
                offTime4 = 0;
                //后室报警判断
                if (hswdMax4 > 0 && CommonClass.pmDict["4号加热炉"].hswdCur > hswdMax4 && hstag)
                {
                    splitContainer2.Panel1.BackColor = Color.Red;
                    WaringSol(CommonClass.pmDict["4号加热炉"], "后室温度超过温度上限！" + "后室温度：" + ((double)(CommonClass.pmDict["4号加热炉"].hswdCur)).ToString("N2") + "℃",
                                "后室上限温度：" + hswdMax4.ToString("N2") + "℃");
                    hstag = false;
                }
                else if (hswdMax4 > 0 && CommonClass.pmDict["4号加热炉"].hswdCur < hswdMax4 && !hstag)
                {
                    hstag = true;
                    pictureBox1.BackColor = Color.White;
                    splitContainer2.Panel1.BackColor = Color.Black;
                }
                //油槽报警判断
                if (ycwdMax4 > 0 && CommonClass.pmDict["4号加热炉"].ycwdCur > ycwdMax4 && YcTag)
                {
                    splitContainer3.Panel1.BackColor = Color.Red;
                    WaringSol(CommonClass.pmDict["4号加热炉"], "油槽温度超过温度上限！" + "油槽温度：" + ((double)(CommonClass.pmDict["4号加热炉"].ycwdCur)).ToString("N2") + "℃",
                            "油槽上限温度：" + ycwdMax3.ToString("N2") + "℃");
                    YcTag = false;
                }
                else if (ycwdMax4 > 0 && CommonClass.pmDict["4号加热炉"].ycwdCur < ycwdMax4 && !YcTag)
                {
                    YcTag = true;
                    pictureBox1.BackColor = Color.White;
                    splitContainer3.Panel1.BackColor = Color.Black;
                }

                state_val4.Text = "运行";
                state_val4.ForeColor = Color.Black;
                try
                {
                    AddPoint(CommonClass.pmDict["4号加热炉"], zedGraphControl4);
                }
                catch (Exception ex)
                {
                    CommonClass.LogError(ex.ToString());
                }

                WorkStGet(CommonClass.pmDict["4号加热炉"]);//状态解析
            }
            if (offTime4 > 30)
            {
                prdStClear("4号加热炉");
            }

        }

        private void zedgraphControl_MouseDoubleClick(object sender, MouseEventArgs e)
        {
            myPane1.YAxis.Scale.Max = ymax;
            myPane1.YAxis.Scale.Min = ymin;
            myPane1.XAxis.Scale.Max = (double)x_end;
            myPane1.XAxis.Scale.Min = (double)x_start;
        }

        private void room_real_TextChanged(object sender, EventArgs e)
        {

        }

        private void Form2_FormClosing(object sender, FormClosingEventArgs e)
        {
            e.Cancel = true;
            this.Hide();
        }

        private void button_war_his_Click(object sender, EventArgs e)
        {
            //将警报界面显示出来
            WarForm warform = new WarForm(device_num, devNm);
            jumpEnable = false;
            warform.ShowDialog();
        }

        private void WaringSol(ht_pmmr pmmr, string info, string reason)
        {
            pictureBox1.BackColor = Color.Yellow;
            //warPanel.Visible = true;
            string msg = DateTime.Now.ToString("yyyy/MM/dd HH:mm:ss") + "\r\n" + info;
            //tbxWarInfo.Text = msg;
        }


        private void HistoryAdd(XDate time, float room_temp_real, float oil_temp_real, float cp_value_real, float cmv_value)
        {
            XDate now = time;
            double add_time = (double)now;

            list_room_real.Add(add_time, Convert.ToDouble(room_temp_real * CommonClass.hsy));
            list_oil_real.Add(add_time, Convert.ToDouble(oil_temp_real * CommonClass.ycy));
            list_cp_real.Add(add_time, Convert.ToDouble(cp_value_real * CommonClass.cpy));
            list_cmv.Add(add_time, Convert.ToDouble(cmv_value * CommonClass.cmvy));
        }

        # region 零件状态处理及显示
        double styctp;//油槽临时温度
        int yctimes;//油槽升温计次
        DateTime S3Dt;//淬火时间
        DateTime S4Dt;//沥油时间
        private void WorkStGet(ht_pmmr pmmr)
        {
            if (rst.S0 == "T" && pmmr.hswdCur <= 700)
            {
                rst.S1 = "T";
                StShow("S1");
            }
            else if (rst.S1 == "T" && pmmr.hswdCur >= pmmr.hswdSet)
            {
                rst.S2 = "T";
                StShow("S2");
                styctp = Convert.ToDouble(pmmr.ycwdCur??0);
                yctimes = 0 ;
            }
            else if (rst.S2 == "T")
            {
                if (pmmr.ycwdCur - styctp > 1)
                {
                    if (yctimes > 3 || pmmr.ycwdCur - styctp > 3)
                    {
                        rst.S3 = "T";
                        StShow("S3");
                        S3Dt = DateTime.Now;
                    }
                    else
                    {
                        styctp = Convert.ToDouble(pmmr.ycwdCur ?? 0);
                        yctimes++;
                    }
                }
                else
                {
                    yctimes = 0;
                    styctp = Convert.ToDouble(pmmr.ycwdCur ?? 0);
                }
            }
            else if (rst.S3 == "T" && (DateTime.Now - S3Dt).TotalMinutes >= 15)
            {
                rst.S4 = "T";
                StShow("S4");
                S4Dt = DateTime.Now;
            }
            else if (rst.S4 == "T" && (DateTime.Now - S4Dt).TotalMinutes >= 15)
            {
                rst.S0 = "T";
                StShow("S0");
            }
        }

        ht_devSetTableAdapter devStTa = new ht_devSetTableAdapter();
        private void StShow(string st)
        {
            try
            {
                StReSet();
                switch (st)
                {
                    case "S0":
                        devStTa.UpdatePrdSt(st, devNm);
                        stpb0.BackgroundImage = Properties.Resources.runnode;
                        curPic = stpb0;
                        stlb0.ForeColor = Color.Black;
                        break;
                    case "S1":
                        devStTa.UpdatePrdSt(st, devNm);
                        stpb1.BackgroundImage = Properties.Resources.runnode;
                        curPic = stpb1;
                        stlb1.ForeColor = Color.Black;
                        break;
                    case "S2":
                        devStTa.UpdatePrdSt(st, devNm);
                        stpb2.BackgroundImage = Properties.Resources.runnode;
                        stpb22.BackgroundImage = Properties.Resources.runnode;
                        stlb2.ForeColor = Color.Black;
                        stlb22.ForeColor = Color.Black;
                        curPic = stpb2;
                        break;
                    case "S3":
                        devStTa.UpdatePrdSt(st, devNm);
                        stpb3.BackgroundImage = Properties.Resources.runnode;
                        stlb3.ForeColor = Color.Black;
                        curPic = stpb3;
                        break;
                    case "S4":
                        devStTa.UpdatePrdSt(st, devNm);
                        stpb4.BackgroundImage = Properties.Resources.runnode;
                        stlb4.ForeColor = Color.Black;
                        curPic = stpb4;
                        break;
                }
            }
            catch (Exception ex)
            {
                CommonClass.LogError(ex.ToString());
            }
        }

        private void StReSet()
        {
            stpb0.BackgroundImage = Properties.Resources.node;
            stpb1.BackgroundImage = Properties.Resources.node;
            stpb2.BackgroundImage = Properties.Resources.node;
            stpb22.BackgroundImage = Properties.Resources.node;
            stpb3.BackgroundImage = Properties.Resources.node;
            stpb4.BackgroundImage = Properties.Resources.node;

            stlb0.ForeColor = Color.Silver;
            stlb1.ForeColor = Color.Silver;
            stlb2.ForeColor = Color.Silver;
            stlb22.ForeColor = Color.Silver;
            stlb3.ForeColor = Color.Silver;
            stlb4.ForeColor = Color.Silver;

            curPic = null;
        }

        PictureBox curPic = null;
        private void pictimer_Tick(object sender, EventArgs e)
        {
            if (curPic == null)
            { return; }
            if (curPic.Name == stpb2.Name)
            {
                if (stpb2.BackgroundImage == null)
                {
                    stpb2.BackgroundImage = Properties.Resources.runnode;
                    stpb22.BackgroundImage = Properties.Resources.runnode;
                }
                else
                {
                    stpb22.BackgroundImage = null;
                    stpb2.BackgroundImage = null;
                }
            }
            else
            {
                if (curPic.BackgroundImage == null)
                {
                    curPic.BackgroundImage = Properties.Resources.runnode;
                }
                else
                {
                    curPic.BackgroundImage = null;
                }
            }
        }
        #endregion

        private void StSetTSM_Click(object sender, EventArgs e)
        {
            PictureBox myPb;
            try
            {
                myPb = (PictureBox)(StSetMenuStrip.SourceControl);
            }
            catch 
            {
                MessageBox.Show("选择错误");    
                return; 
            }
            switch (myPb.Name)
            {
                case "stpb0":
                    rst.S0 = "T";
                    StShow("S0");
                    break;
                case "stpb1":
                    rst.S1 = "T";
                    StShow("S1");
                    break;
                case "stpb2":
                    rst.S2 = "T";
                    StShow("S2");
                    styctp = Convert.ToDouble(oil_real1.Text ?? "0");
                    yctimes = 0;
                    break;
                case "stpb22":
                    rst.S2 = "T";
                    StShow("S2");
                    styctp = Convert.ToDouble(oil_real1.Text ?? "0");
                    yctimes = 0;
                    break;
                case "stpb3":
                    rst.S3 = "T";
                    StShow("S3");
                    S3Dt = DateTime.Now;
                    break;
                case "stpb4":
                    rst.S4 = "T";
                    StShow("S4");
                    S4Dt = DateTime.Now;
                    break;
            }
        }

        private void prdStClear(string devNm)
        {
            rst.ReSet();
            StReSet();
            devStTa.UpdatePrdSt("", devNm);
        }

        private void StSetMenuStrip_Opening(object sender, CancelEventArgs e)
        {
            jumpEnable = false;
        }

       

     

    }
}
